package com.tianheng.modbus.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import java.util.HashMap;
import java.util.Map;

public enum ProtocolTypeEnum {
    MODBUS_TCP_IP("Modbus TCP/IP"),
    MODBUS_RTU_ASCII_OVER_TCP_IP("Modbus RTU/ASCII Over TCP/IP"),
    ;
    private String value;

    ProtocolTypeEnum(String name) {
        this.value = name;
    }

    @JsonCreator
    public static ProtocolTypeEnum creator(String name){
       return ProtocolTypeEnum.valueOf(name);
    }

    @JsonValue
    public Map<String, String> toJsonValue(){
        Map map = new HashMap<String, String>();
        map.put("code", this.name());
        map.put("name", this.value);
        return map;
    }
}
